// 商户信息，权限等数据处理

import { TestConfig } from '../common/testConfig.js';
import { Profile } from "../user/profile";
import { Engine } from "../engine";
import { login } from '../../network/api.js';
import { CommunicationPageData, ApiReturnStruct, NetworkParser, DataPage } from '../../network/communicationConverter.js';
import { TestSimulateData } from '../testMgr/testSimulateData.js';
import { MessageUtil } from '@/utils/MessageUtil.js';

export class MerchantUiAction {
    async getLoginData(params) {
        if (TestConfig.simMerchantAndAccount) {
            return (new TestSimulateData()).simLoginProfileAndMerchant();
        }
        else {
            const res = await login({
                ...params,
            });

            const parseResult = NetworkParser.parseNetworkResult(res, Profile.fromJson);

            if (parseResult && parseResult.data) {
                return parseResult.data;               
            }
            else{
                console.log('登录失败:',parseResult.resErr);
                MessageUtil.showErrorMsg(parseResult.resErr);
            }
        }

        return null;
    }
}